package com.coco.homework;

import java.util.Arrays;
import java.util.List;

import com.coco.homework.ex.RomanNumberNotFoundException;

/**
 * 
 * @author YanpHu
 *
 */
public enum RomanNumber {

	EOF(0),I(1), V(5), X(10), L(50), C(100), D(500), M(1000);

	private int val;

	RomanNumber(int val) {
		this.val = val;
	}

	public int getVal() {
		return val;
	}

	private static List<RomanNumber> CAN_SUBTRACT_I = Arrays.asList(RomanNumber.X,RomanNumber.V);
	private static List<RomanNumber> CAN_SUBTRACT_X = Arrays.asList(RomanNumber.L,RomanNumber.C);
	private static List<RomanNumber> CAN_SUBTRACT_C = Arrays.asList(RomanNumber.D,RomanNumber.M);

	public static boolean canSubtractI(RomanNumber rn) {
		return CAN_SUBTRACT_I.contains(rn);
	}
	
	public static boolean canSubtractX(RomanNumber rn) {
		return CAN_SUBTRACT_X.contains(rn);
	}
	
	public static boolean canSubtractC(RomanNumber rn) {
		return CAN_SUBTRACT_C.contains(rn);
	}
	
	
	public static RomanNumber of(char romanNumber) {
		return of(String.valueOf(romanNumber));
	}
	
	public static RomanNumber of(String romanNumber) {
		if (romanNumber.equals(String.valueOf(Context.EOF_CHAR))) {
			return RomanNumber.EOF;
		}
		for (RomanNumber r : RomanNumber.values()) {
			if (r.name().equals(romanNumber)) {
				return r;
			}
		}
		throw new RomanNumberNotFoundException(romanNumber);
	}
}
